//
//  NSObject+Property.h
//  自动生成property分类
//
//  Created by kepuna on 14/10/22.
//  Copyright © 2014年 kepuna. All rights reserved.
//  通过解析字典自动生成属性代码


#import "NSObject+Property.h"

@implementation NSObject (Property)

+ (void)zj_propertyCodeWithDict:(NSDictionary *)dict {
    
    NSMutableString *strM = [NSMutableString string];
    [dict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull propertyName, id  _Nonnull value, BOOL * _Nonnull stop) {
       
        NSLog(@"#### %@ #### %@",propertyName,[value class]);
        
        NSString *code;
        if ([value isKindOfClass:NSClassFromString(@"__NSCFString")] ||
            [value isKindOfClass:NSClassFromString(@"NSTaggedPointerString")]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@;",propertyName]
            ;
        } else if ([value isKindOfClass:NSClassFromString(@"__NSCFNumber")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) NSInteger %@;",propertyName]
            ;
        } else if ([value isKindOfClass:NSClassFromString(@"__NSCFArray")] || [value isKindOfClass:NSClassFromString(@"__NSArrayI")] ||
             [value isKindOfClass:NSClassFromString(@"__NSSingleObjectArrayI")]      ){
            code = [NSString stringWithFormat:@"@property (nonatomic, copy) NSArray *%@;",propertyName]
            ;
        } else if ([value isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;",propertyName]
            ;
        } else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",propertyName]
            ;
        }
        [strM appendFormat:@"\n%@\n",code];
    }];
    NSLog(@"%@",strM);
}

@end
